import { ref } from 'vue'
import translations from './translations'

// 创建响应式语言状态
const currentLanguage = ref('zh')

// 翻译函数
const t = (key: string) => {
  return translations[currentLanguage.value as keyof typeof translations][key as keyof typeof translations.zh] || key
}

// 切换语言的函数
const setLanguage = (language: string) => {
  currentLanguage.value = language
  // 保存语言选择到本地存储
  localStorage.setItem('selectedLanguage', language)
}

// 恢复保存的语言设置
const savedLanguage = localStorage.getItem('selectedLanguage')
if (savedLanguage) {
  currentLanguage.value = savedLanguage
}

export { t, setLanguage, currentLanguage }